<!-- <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>js_1_catch</title>
        <script type="text/javascript">
            var txt="";
            function message(){
                try {
                    adddlert("Welcome guest!");
                } catch (err) {
                    txt="本页有一个错误。\n\n";
                    txt+="错误描述:"+err.message+"\n\n";
                    txt+="点击确定继续。\n\n";
                    alert(txt);
                }
            }
        </script>
    </head>
    <body>
        <input type="button" value="查看消息" onclick="message()"/>
    </body>
</html> -->

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>js_1_catch</title>
</head>

<body>
    <script type="text/javascript">
        function myFunction() {
            try {
                var x = document.getElementById('demo').value;
                if (x == "") throw "empty";
                if (isNaN(x)) throw "not a number";
                if (x > 10) throw "too high";
                if (x < 5) throw "too low";
            } catch (err) {
                var y = document.getElementById("mess");
                y.innerHTML = "Error:" + err + ",";
            }
        }
    </script>
    <h1>My first javascript</h1>
    <p>Please input a number between 5 and 10</p>
    <input id="demo" type="text">
    <button type="button" onclick="myFunction()">test input</button>
    <p id="mess"></p>
</body>

</html>
